
package gui.view;
import gui.componenten.JListWithToolTip;
import gui.controller.MainController;
import gui.controller.MenuController;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Window;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.beans.EventHandler;

import javax.swing.ButtonGroup;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.KeyStroke;
import javax.swing.ListSelectionModel;
import javax.swing.ScrollPaneConstants;
import javax.swing.WindowConstants;

public class MainPanel extends JDialog {
	private JListWithToolTip jGegenstandsSetsList;
	private JListWithToolTip jHeldenList;
	private JListWithToolTip jGegenstandsList;
	private final ButtonGroup buttonGroup = new ButtonGroup();
	


	public MainPanel(Window owner, MainController controller, MenuController menuController) {

        DefaultListModel defaultListModel = new DefaultListModel();

        JMenuBar menuBar = new JMenuBar();

        JMenu mnDatei = new JMenu("Datei");

        JMenuItem menuItem = new JMenuItem("Updatecheck");
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_U, 0));
        menuItem.addActionListener(EventHandler.create(ActionListener.class, menuController, "checkVersion"));
        mnDatei.add(menuItem);

        JMenuItem menuItem2 = new JMenuItem("Importieren aus File");
        menuItem2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, 0));
        menuItem2.addActionListener(EventHandler.create(ActionListener.class, menuController, "importierenAusDatei"));
        mnDatei.add(menuItem2);

        JMenuItem menuItem3 = new JMenuItem("Speichern");
        menuItem3.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, 0));
        menuItem3.addActionListener(EventHandler.create(ActionListener.class, menuController, "speichern"));
        mnDatei.add(menuItem3);
        menuBar.add(mnDatei);

        JMenu menu2 = new JMenu("Hilfe");

        JMenuItem menuItem4 = new JMenuItem("über Ausrüstungsplugin");
        menuItem4.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, 0));
        menuItem4.addActionListener(EventHandler.create(ActionListener.class, menuController, "ueber"));
        
        JMenuItem mntmInfotext = new JMenuItem("Infotext");
        mntmInfotext.addActionListener(EventHandler.create(ActionListener.class, menuController, "zeigeInfo"));
        
        JMenu mnAktionen = new JMenu("Aktionen");
        menuBar.add(mnAktionen);

        JMenuItem mntmSetHinzufgen = new JMenuItem("Set Hinzufügen");
        mntmSetHinzufgen.addActionListener(EventHandler.create(ActionListener.class, controller, "addKlassenSet"));
        mntmSetHinzufgen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, 0));
        mnAktionen.add(mntmSetHinzufgen);
        
        JMenuItem mntmSetBearbeiten = new JMenuItem("Set Bearbeiten");
        mntmSetBearbeiten.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, 0));
        mntmSetBearbeiten.addActionListener(EventHandler.create(ActionListener.class, controller, "editKlassenSet"));
        mnAktionen.add(mntmSetBearbeiten);
        
        JMenuItem mntmSetLschen = new JMenuItem("Set Löschen");
        mntmSetLschen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, 0));
        mntmSetLschen.addActionListener(EventHandler.create(ActionListener.class, controller, "delKlassenSet"));
        mnAktionen.add(mntmSetLschen);
        
        JMenuItem mntmSetDemHeld = new JMenuItem("Set dem Held hinzufügen");
        mntmSetDemHeld.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H, 0));
        mntmSetDemHeld.addActionListener(EventHandler.create(ActionListener.class, controller, "addItemsZumHeld"));
        mnAktionen.add(mntmSetDemHeld);
        
        JMenuItem mntmSetImportieren = new JMenuItem("Set importieren");
        mntmSetImportieren.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, 0));
        mntmSetImportieren.addActionListener(EventHandler.create(ActionListener.class, controller, "importVomHeld"));
        mnAktionen.add(mntmSetImportieren);

        JMenuItem mntmSchlieen = new JMenuItem("Schließen");
        mntmSchlieen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, 0));
        mntmSchlieen.addActionListener(EventHandler.create(ActionListener.class, controller, "close"));
        mnAktionen.add(mntmSchlieen);
        mntmInfotext.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, 0));
        menu2.add(mntmInfotext);
        menu2.add(menuItem4);
        menuBar.add(menu2);
        this.setJMenuBar(menuBar);

        JPanel contentPane = (JPanel) getContentPane();
        GridBagLayout gridBagLayout = new GridBagLayout();
        gridBagLayout.columnWidths = new int[]{250, 30, 250, 250, 0};
        gridBagLayout.rowHeights = new int[]{14, 30, 0, 0};
        gridBagLayout.columnWeights = new double[]{1.0, 0.0, 1.0, 1.0, Double.MIN_VALUE};
        gridBagLayout.rowWeights = new double[]{0.0, 1.0, 0.0, Double.MIN_VALUE};
        getContentPane().setLayout(gridBagLayout);
                                                
                                                        JLabel label3 = new JLabel();
                                                        label3.setText("Gegenstandssets");
                                                        GridBagConstraints gbc_label3 = new GridBagConstraints();
                                                        gbc_label3.anchor = GridBagConstraints.NORTH;
                                                        gbc_label3.insets = new Insets(0, 0, 5, 5);
                                                        gbc_label3.gridx = 0;
                                                        gbc_label3.gridy = 0;
                                                        contentPane.add(label3, gbc_label3);
                                        
                                                JLabel label2 = new JLabel();
                                                label2.setText("Gegenstände des Sets");
                                                GridBagConstraints gbc_label2 = new GridBagConstraints();
                                                gbc_label2.anchor = GridBagConstraints.NORTH;
                                                gbc_label2.insets = new Insets(0, 0, 5, 5);
                                                gbc_label2.gridx = 2;
                                                gbc_label2.gridy = 0;
                                                contentPane.add(label2, gbc_label2);
                                
                                        JLabel label = new JLabel();
                                        label.setText("Helden");
                                        GridBagConstraints gbc_label = new GridBagConstraints();
                                        gbc_label.anchor = GridBagConstraints.NORTH;
                                        gbc_label.insets = new Insets(0, 0, 5, 0);
                                        gbc_label.gridx = 3;
                                        gbc_label.gridy = 0;
                                        contentPane.add(label, gbc_label);
                        
                                jGegenstandsSetsList = new JListWithToolTip();
                                jGegenstandsSetsList.setDragEnabled(true);
                                jGegenstandsSetsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
                                
                                        JScrollPane scrollPane3 = new JScrollPane(jGegenstandsSetsList);
                                        scrollPane3.setPreferredSize(new Dimension(23, 23));
                                        scrollPane3.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
                                        GridBagConstraints gbc_scrollPane3 = new GridBagConstraints();
                                        gbc_scrollPane3.fill = GridBagConstraints.BOTH;
                                        gbc_scrollPane3.insets = new Insets(0, 0, 5, 5);
                                        gbc_scrollPane3.gridx = 0;
                                        gbc_scrollPane3.gridy = 1;
                                        contentPane.add(scrollPane3, gbc_scrollPane3);
                                        
                                                JScrollPane scrollPane = new JScrollPane();
                                                scrollPane.setPreferredSize(new Dimension(23, 23));
                                                scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
                                                GridBagConstraints gbc_scrollPane = new GridBagConstraints();
                                                gbc_scrollPane.fill = GridBagConstraints.BOTH;
                                                gbc_scrollPane.insets = new Insets(0, 0, 5, 5);
                                                gbc_scrollPane.gridwidth = 2;
                                                gbc_scrollPane.gridx = 1;
                                                gbc_scrollPane.gridy = 1;
                                                contentPane.add(scrollPane, gbc_scrollPane);
                                                
                                                        jGegenstandsList = new JListWithToolTip();
                                                        scrollPane.setViewportView(jGegenstandsList);
                                                        jGegenstandsList.setDragEnabled(true);
                                                        jGegenstandsList.setModel(defaultListModel);
                                                        jGegenstandsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
                                jHeldenList = new JListWithToolTip();
                                jHeldenList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
                              
                                        JScrollPane scrollPane2 = new JScrollPane(jHeldenList);
                                        scrollPane2.setPreferredSize(new Dimension(23, 23));
                                        scrollPane2.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
                                        GridBagConstraints gbc_scrollPane2 = new GridBagConstraints();
                                        gbc_scrollPane2.fill = GridBagConstraints.BOTH;
                                        gbc_scrollPane2.insets = new Insets(0, 0, 5, 0);
                                        gbc_scrollPane2.gridx = 3;
                                        gbc_scrollPane2.gridy = 1;
                                        contentPane.add(scrollPane2, gbc_scrollPane2);
                                        
                                        JPanel panel = new JPanel();
                                        GridBagConstraints gbc_panel = new GridBagConstraints();
                                        gbc_panel.gridwidth = 2;
                                        gbc_panel.fill = GridBagConstraints.BOTH;
                                        gbc_panel.insets = new Insets(0, 0, 0, 5);
                                        gbc_panel.gridx = 0;
                                        gbc_panel.gridy = 2;
                                        getContentPane().add(panel, gbc_panel);
                                        GridBagLayout gbl_panel = new GridBagLayout();
                                        gbl_panel.columnWidths = new int[]{85, 30, 51, 30, 30, 0};
                                        gbl_panel.rowHeights = new int[]{0, 0, 0};
                                        gbl_panel.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
                                        gbl_panel.rowWeights = new double[]{0.0, 0.0, Double.MIN_VALUE};
                                        panel.setLayout(gbl_panel);
                                        
                                                JButton button2 = new JButton();
                                                GridBagConstraints gbc_button2 = new GridBagConstraints();
                                                gbc_button2.anchor = GridBagConstraints.NORTH;
                                                gbc_button2.fill = GridBagConstraints.HORIZONTAL;
                                                gbc_button2.insets = new Insets(5, 5, 5, 5);
                                                gbc_button2.gridx = 0;
                                                gbc_button2.gridy = 0;
                                               
                                                panel.add(button2, gbc_button2);
                                                button2.setText("Löschen (D)");
                                                
                                                        JButton button4 = new JButton();
                                                        GridBagConstraints gbc_button4 = new GridBagConstraints();
                                                        gbc_button4.insets = new Insets(5, 5, 5, 5);
                                                        gbc_button4.anchor = GridBagConstraints.NORTH;
                                                        gbc_button4.fill = GridBagConstraints.HORIZONTAL;
                                                        gbc_button4.gridwidth = 3;
                                                        gbc_button4.gridx = 2;
                                                        gbc_button4.gridy = 0;
                                                        panel.add(button4, gbc_button4);
                                                        button4.setText("Hinzufügen (A)");
                                                        
                                                                JButton btnSchlieenC = new JButton();
                                                                GridBagConstraints gbc_btnSchlieenC = new GridBagConstraints();
                                                                gbc_btnSchlieenC.anchor = GridBagConstraints.SOUTH;
                                                                gbc_btnSchlieenC.fill = GridBagConstraints.HORIZONTAL;
                                                                gbc_btnSchlieenC.insets = new Insets(5, 5, 5, 5);
                                                                gbc_btnSchlieenC.gridx = 0;
                                                                gbc_btnSchlieenC.gridy = 1;
                                                                panel.add(btnSchlieenC, gbc_btnSchlieenC);
                                                                btnSchlieenC.setText("Schließen (C)");
                                                                
                                                                        JButton button5 = new JButton();
                                                                        GridBagConstraints gbc_button5 = new GridBagConstraints();
                                                                        gbc_button5.anchor = GridBagConstraints.SOUTH;
                                                                        gbc_button5.fill = GridBagConstraints.HORIZONTAL;
                                                                        gbc_button5.gridwidth = 3;
                                                                        gbc_button5.insets = new Insets(5, 5, 5, 5);
                                                                        gbc_button5.gridx = 2;
                                                                        gbc_button5.gridy = 1;
                                                                        panel.add(button5, gbc_button5);
                                                                        button5.setText("Bearbeiten (E)");
                                                                        button5.addActionListener(EventHandler.create(ActionListener.class, controller, "editKlassenSet"));
                                                                btnSchlieenC.addActionListener(EventHandler.create(ActionListener.class, controller, "close"));
                                                        button4.addActionListener(EventHandler.create(ActionListener.class, controller, "addKlassenSet"));
                                                button2.addActionListener(EventHandler.create(ActionListener.class, controller, "delKlassenSet"));
                                        
                                        JPanel panel_1 = new JPanel();
                                        GridBagConstraints gbc_panel_1 = new GridBagConstraints();
                                        gbc_panel_1.anchor = GridBagConstraints.EAST;
                                        gbc_panel_1.gridwidth = 2;
                                        gbc_panel_1.fill = GridBagConstraints.VERTICAL;
                                        gbc_panel_1.gridx = 2;
                                        gbc_panel_1.gridy = 2;
                                        getContentPane().add(panel_1, gbc_panel_1);
                                        GridBagLayout gbl_panel_1 = new GridBagLayout();
                                        gbl_panel_1.columnWidths = new int[]{250, 0};
                                        gbl_panel_1.rowHeights = new int[]{0, 0, 0};
                                        gbl_panel_1.columnWeights = new double[]{1.0, Double.MIN_VALUE};
                                        gbl_panel_1.rowWeights = new double[]{0.0, 0.0, Double.MIN_VALUE};
                                        panel_1.setLayout(gbl_panel_1);
                                        
                                                JButton button3 = new JButton();
                                                GridBagConstraints gbc_button3 = new GridBagConstraints();
                                                gbc_button3.anchor = GridBagConstraints.NORTH;
                                                gbc_button3.fill = GridBagConstraints.HORIZONTAL;
                                                gbc_button3.insets = new Insets(0, 0, 5, 0);
                                                gbc_button3.gridx = 0;
                                                gbc_button3.gridy = 0;
                                                panel_1.add(button3, gbc_button3);
                                                buttonGroup.add(button3);
                                                button3.setText("Gegenstandsset dem Helden hinzufügen  (H)");
                                                
                                                        JButton importieren = new JButton();
                                                        GridBagConstraints gbc_importieren = new GridBagConstraints();
                                                        gbc_importieren.fill = GridBagConstraints.HORIZONTAL;
                                                        gbc_importieren.gridx = 0;
                                                        gbc_importieren.gridy = 1;
                                                        panel_1.add(importieren, gbc_importieren);
                                                        buttonGroup.add(importieren);
                                                        importieren.setName("Importieren");
                                                        importieren.setText("Gegenstandsset eines Helden importieren (I)");
                                                        importieren.addActionListener(EventHandler.create(ActionListener.class, controller, "importVomHeld"));
                                                button3.addActionListener(EventHandler.create(ActionListener.class, controller, "addItemsZumHeld"));
        this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        this.setTitle("AusrüstungsPlugin");
    }

	public JListWithToolTip getJItemSetsList() {
		return jGegenstandsSetsList;
	}
	public JListWithToolTip getJHeldenList() {
		return jHeldenList;
	}
	public JListWithToolTip getJGegenstandsList() {
		return jGegenstandsList;
	}
}
